package com.randi.generator.service.impl;

import com.randi.generator.entity.GenTableColumn;
import com.randi.generator.mapper.GenTableColumnMapper;
import com.randi.generator.service.IGenTableColumnService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class GenTableColumnService implements IGenTableColumnService {

    @Resource
    private GenTableColumnMapper genTableColumnMapper;

    /**
     * 查询业务列表
     *
     * @return 业务集合
     */
    @Override
    public List<GenTableColumn> selectGenTableColumnList() {
        return genTableColumnMapper.selectList(null);
    }


    /**
     * 插入数据
     *
     * @param genTableColumn GenTableColumn
     * @return 结果
     */
    @Override
    @Transactional
    public int insertGenTableColumn(GenTableColumn genTableColumn) {
        genTableColumn.setCreateTime(new Date());
        return genTableColumnMapper.insert(genTableColumn);
    }

    /**
     * 更新数据
     *
     * @param genTableColumn GenTableColumn
     * @return 结果
     */
    @Override
    public int updateGenTableColumn(GenTableColumn genTableColumn) {
        genTableColumn.setUpdateTime(new Date());
        return genTableColumnMapper.updateById(genTableColumn);
    }

    /**
     * 删除数据
     *
     * @param  columnId columnId
     * @return 结果
     */
    @Override
    public int deleteGenTableColumn(Long columnId) {
        return genTableColumnMapper.deleteById(columnId);
    }

    /**
     * 批量删除数据
     *
     * @param ids ids
     * @return 结果
     */
    @Override
    public int deleteBatchGenTableColumn(List<Long> ids) {
        return genTableColumnMapper.deleteBatchIds(ids);
    }

    /**
     * 根据表ID删除数据
     *
     * @param tableId tableId
     * @return 结果
     */
    @Override
    public int deleteGenTableColumnByTableId(Long tableId) {
        List<Long> tableIds = Collections.singletonList(tableId);
        return this.deleteBatchByTableIds(tableIds);
    }

    /**
     * 根据批量表ID删除行数据
     *
     * @param tableIds tableIds
     * @return 结果
     */
    @Override
    public int deleteBatchByTableIds(List<Long> tableIds) {
        return genTableColumnMapper.deleteBatchByTableIds(tableIds);
    }


}
